<template>
	<view class="">
		<view class="button-group">
			<button size="mini" type="warn" @tap="start">打开连接</button>
			<button size="mini" type="primary" @tap="send">发送当前时间</button>
			<button size="mini" type="default" @tap="closeSocket">关闭连接</button>
		</view>
		<!-- {{dataSocket}} -->
		<BottomTips txt="*** 需求要求 进入小程序就打开 ***" />
		<BottomTips txt="可在 App.vue内 onLaunch(){} 方法内调用" />
	</view>
</template>

<script>
	import BottomTips from '@/components/bottom-tips.vue'
	import { mapState } from 'vuex'
	export default {
		components:{ BottomTips },
		data(){
			return {
				socketOpen: false,		// 默认未打开
				socketTask: null,
			}
		},
		onLoad() {
			
		},
		computed:{
			...mapState(['dataSocket'])
		},
		methods:{
			start(){
				this.$store.dispatch('initSocket',{url:'ws://190.168.1.57:8082',mid: '1',token: ''})
			},
			send(){			
				this.$store.dispatch('send',{data:`当前时间是${new Date().getTime()}`})
			},
			closeSocket(){
				this.$store.dispatch('closeSocket')
			},
			
			add(){
				this.$store.dispatch('initSocket',{url:'ws://190.168.1.57:8082',mid: '1',token: ''})
			}
		}
	}
</script>

<style scoped lang="scss">
	.button-group{display: flex;justify-content: space-between;padding-top: 20rpx;}
</style>